<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div>看控制台输出</div>

    <script>
        let info = {
            name: 'zs',
            age: 10,
            address: '武汉',
            phone: 15888888888
        }

        delete info.address
        console.log(info);

        // 最简单的方法
        let info2 = {
            name: '东方不败',
            age: 10,
            address: '武汉'
        }
        delete info2.address // 删除address
        console.log(info2);


        // 返回不包含键名：address 的新对象
        let selectInfo = ['name', 'age', 'phone'] // 此处为保留的键名信息
        let list = Object.keys(info)
            .filter((key) => selectInfo.includes(key))
            .reduce((obj, key) => {
                return Object.assign(obj, {
                    [key]: info[key]
                })
            }, {})
        console.log(list);


        // 返回只包含键名：address 的新对象
        let list2 = Object.keys(info)
            .filter((key) => key.includes('address')) // 此处为只保留的键名信息
            .reduce((obj, key) => {
                return Object.assign(obj, {
                    [key]: info[key]
                })
            }, {})
        console.log(list2);
    </script>


</body>

</html>